//
//  ST_EditGeneralInfoCell.swift
//  btvideo
//
//  Created by mac on 2020/1/8.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift
import HandyJSON
import SwiftyAttributes

class ST_EditGeneralInfoCell: UITableViewCell {

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        self.selectionStyle = .none
        
        contentView.addSubview(info_label)
//        contentView.addSubview(icon_image_view)
        contentView.addSubview(content_label)
        contentView.addSubview(nav_image_view)
        
        
//        icon_image_view.snp.makeConstraints { (make) in
//            make.left.equalToSuperview().offset(25)
//            make.centerY.equalToSuperview()
//            make.width.height.equalTo(22)
//        }
        
        info_label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
        }
        content_label.snp.makeConstraints { (make) in
            make.left.equalTo(info_label.snp.right).offset(10)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-35)
        }
        nav_image_view.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-15)
        }
        
        /*
        let line = UIView()
        line.backgroundColor = Color.init(hex: 0xF2F4F7)
        contentView.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalTo(info_label).offset(-5)
            make.height.equalTo(1)
            make.right.bottom.equalToSuperview()
        }*/
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var info_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#ACB4C0")
//        control.numberOfLines = 0
        control.textAlignment = .left
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate let placeholderColor = Color.init(hexString: "#ED3E58")!
    
    fileprivate let contentLabelColor = Color.init(hexString: "#61666F")!
    
    lazy var content_label:UIButton = {
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setTitleColorForAllStates(placeholderColor)
        control.setTitleForAllStates("填写")
        control.setTitleColor(contentLabelColor, for: UIControl.State.selected)
        control.isUserInteractionEnabled = false
        control.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
    
    
    lazy var nav_image_view:UIImageView = {
        let control = UIImageView()
        control.image = ST_ImageUtils.imageName("mycenter_icon_下一页")
        return control
    }()

    lazy var icon_image_view:UIImageView = {
        let control = UIImageView()
//        control.contentMode = .scaleAspectFill
//        control.clipsToBounds = true
//        control.backgroundColor = Color.random
        return control
    }()

    
    var model  = ST_EditGeneralInfoCellModel(){
        didSet{
            
            info_label.text = model.displayKey
            
            content_label.isSelected = !model.displayValue.isEmpty
            
            content_label.setTitle(model.displayValue, for: UIControl.State.selected)
            
        }
    }
    
    var model_copy:ST_EditGeneralInfoCellModel_Copy?{
        didSet{
            
            guard let m = model_copy else { return  }
            
            info_label.text = m.displayKey
            
            content_label.isSelected = !m.displayValue.isEmpty
            
            content_label.setTitle(m.displayValue, for: UIControl.State.selected)
        }
    }
    
    
    
}



class ST_EditGeneralEmptyTextCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .none
        
        contentView.addSubview(info_label)
        contentView.addSubview(click_btn)
        
        info_label.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(14)
            make.centerX.equalToSuperview()
        }
        
        click_btn.snp.makeConstraints { (make) in
            make.top.equalTo(info_label.snp.bottom).offset(12)
            make.centerX.equalToSuperview()
            make.height.equalTo(35)
            make.width.equalTo(196)
        }
        
        click_btn.isUserInteractionEnabled = false
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var info_label:UILabel = {
        let control = UILabel.init()
        control.text = "还没有内容哦"
        control.textColor = UIColor.init(hexString: "#ACB4C0")
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
    
    

    lazy var click_btn:UIButton = {
            
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.backgroundColor = UIColor.init(hexString: "#FEC207")
        control.cornerRadius = 35/2.0
//        control.borderColor = Color.init(white: 0, alpha: 0.1)
//        control.borderWidth = 1
        control.setTitleForAllStates("")
        control.setTitleColorForAllStates(UIColor.white)
        control.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.semibold)
        control.addTarget(self, action: #selector(supplement_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    var supplement_closure:((ST_EditGeneralEmptyTextCell)->())?
    
    @objc func supplement_handle(){
        
        supplement_closure?(self)
    }
    
    
    var model = ST_EditGeneralInfoCellModel(){
        didSet{
            
            if model.modifyKey == "sign"{
                click_btn.snp.updateConstraints { (make) in
                    make.width.equalTo(168)
                }
            }else{
                click_btn.snp.updateConstraints { (make) in
                    make.width.equalTo(196)
                }
            }
            click_btn.setTitleForAllStates(model.reminderString)
        }
    }
    
    
    var model_copy:EditGeneralEmptyTextCellModel_Copy?{
        didSet{
            
            guard let m = model_copy else { return  }
            
            if m.modifyKey == "sign"{
                click_btn.snp.updateConstraints { (make) in
                    make.width.equalTo(168)
                }
            }else{
                click_btn.snp.updateConstraints { (make) in
                    make.width.equalTo(196)
                }
            }
            click_btn.setTitleForAllStates(m.reminderString)
            
        }
    }
}





class ST_EditGeneralTextCell: UITableViewCell {

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        self.selectionStyle = .none
        
        contentView.addSubview(info_label)
        
        info_label.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 15 - ST_EditMyInfoSectionView.sectionLabelBottomEdge, left: 16, bottom: 40-23, right: 15))
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    lazy var info_label:UILabel = {
        let control = UILabel.init()
        control.numberOfLines = 0
        control.backgroundColor = Color.white
//        control.textAlignment = .left
//        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
    
    var model_copy:EditGeneralTextCellModel_Copy?{
        didSet{
            
            guard let m = model_copy else { return  }
          
            info_label.attributedText = m.attributedText
        }
    }
}
